package jp.co.technotree.common.dao;

import java.sql.Connection;
import java.sql.SQLException;

import jp.co.technotree.exception.TransactionException;


public class Transaction {
	private Connection connection = null;
	private int getCallCount = 0;
	
	
	public Transaction(Connection connection){
		this.connection=connection;
		getCallCount = 0;
	}
	
	public Connection getConnection(){
		getCallCount++;
		return this.connection;
	}
	
	public void releaseConnection(){
		getCallCount--;
		
	}
	
	public boolean begin(){
		return false;
		
	}
	
	public boolean commit() throws TransactionException{
		try {
			this.connection.commit();
		} catch (SQLException e) {
			e.printStackTrace();
			throw new TransactionException("コミットエラーが発生しました。:"+e.getMessage());
		}
		return false;
		
	}
	
	public boolean rollback(){
		try {
			this.connection.rollback();
		} catch (SQLException e) {
			e.printStackTrace();
			//throw new TransactionException("ロールバックエラーが発生しました。:"+e.getMessage());
		}
		return false;
	}
	
}
